package com.jacen.fzxs.dao.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.jacen.fzxs.dao.IWallCustomerDao;
import com.jacen.fzxs.entity.WallCustomerEntity;
import com.jacen.fzxs.util.SqlCondition;
import com.jacen.fzxs.util.Utils;

/**
 * 墙体与客户关系
 * @author Jacen
 * 2014年9月3日 下午2:30:30
 */
@Repository
public class WallCustomerDao extends BaseDao<WallCustomerEntity> implements IWallCustomerDao {
	
	
	public List<WallCustomerEntity> getPage(int beginRow, int endRow ,Map<String, ? extends Object> params) {
		
		SqlCondition cond = getPageCondition(params);
		String sql = "select * from t_wall where 1=1 %s ";
		sql = String.format(sql, cond.getCondition());
		sql = SqlCondition.pageSql(sql, beginRow, endRow);
		return executeForList(sql, cond.getParams().toArray());
	}
	
	public long getCount(Map<String, ? extends Object> paramMap) throws SQLException {
		SqlCondition cond = getPageCondition(paramMap);
		String sql = "select count(1) from t_wall where 1=1 %s";
		sql = String.format(sql, cond.getCondition());
		return executeForLong(sql, cond.getParams().toArray());
	}
	
	private SqlCondition getPageCondition(
			Map<String, ? extends Object> mapParams) {
		SqlCondition cond = new SqlCondition();
		if (Utils.paramIsNotEmpty(mapParams.get("orgId")))
			cond.and().like("orgId", mapParams.get("orgId"));
		if (Utils.paramIsNotEmpty(mapParams.get("name")))
			cond.and().like("name", mapParams.get("name"));
		if (Utils.paramIsNotEmpty(mapParams.get("area")))
			cond.and().equal("area", mapParams.get("area"));
		if (Utils.paramIsNotEmpty(mapParams.get("price")))
			cond.and().equal("price", mapParams.get("price"));
		return cond;
	}

	
	
	

}
